<html>

<head>
    <script src="./libs/dat.gui.js"> </script>
    <script src="https://unpkg.com/vue"></script>

    <div id="app">
        {{ fullName }}
    </div>
</head>

<body>
    <script>
        var gui = new dat.GUI();
        gui.open();

        var app = new Vue({
            el: '#app',
            data: {
                firstName: 'Foo',
                lastName: 'Bar',
            },
            watch: {
                firstName: function (val) {
                    this.fullName = val + ' ' + this.lastName
                },
                lastName: function (val) {
                    this.fullName = this.firstName + ' ' + this.lastName
                }
            },
            computed: {
                fullName: {
                    // getter
                    get: function () {
                        return this.firstName + ' ' + this.lastName
                    },
                    // setter
                    set: function (newValue) {
                        var names = newValue.split(' ')
                        this.firstName = names[0]
                        this.lastName = names[names.length - 1]
                    }
                }
            }
        });

        var folder = gui.addFolder('App');
        folder.open();
        folder.add(app.$data, 'firstName').listen();
        folder.add(app.$data, 'lastName').listen();
    </script>
</body>

</html>